package com.jdym.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jdym.R;
import com.jdym.entity.Card;
import com.jdym.entity.CoBank;
import com.jdym.service.CardService;
import com.jdym.service.CoBankService;
import org.apache.velocity.runtime.directive.Foreach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 个人银行卡管理 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-09-20
 */
@RestController
@CrossOrigin
@RequestMapping("/card")
public class CardController {
    @Autowired
    CardService cardService;
    @Autowired
    CoBankService coBankService;

    @RequestMapping("/findAllCard/{firmid}")
    public R findAllCard(@PathVariable int firmid){
       List<Card> cards= cardService.findAllCard(firmid);
        System.out.println("card:"+cards);
        return R.ok().data("cards",cards);
    }

    @RequestMapping("/getBank")
    public R getAllCoBand(){
//        获取到所有的合作银行
        List<CoBank> coBanks= coBankService.getBaseMapper().selectList(null);

        return R.ok().data("coBanks",coBanks);
    }

    @RequestMapping("/addCard/{firmid}")
    public R addCard(Card card, @PathVariable int firmid)
    {

        card.setFirmId(firmid);
        cardService.getBaseMapper().insert(card);
        return R.ok();
    }

    @RequestMapping("/deleteCard/{id}")
    public R deleteCard(@PathVariable int id){
        cardService.getBaseMapper().deleteById(id);
        return R.ok();
    }
}

